package com.example.neo4j.service.impl;

import com.example.neo4j.pojo.node.Share;
import com.example.neo4j.pojo.node.User;
import com.example.neo4j.pojo.util.ResponseInfo;
import com.example.neo4j.repository.ShareRepository;
import com.example.neo4j.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@Service
public class ShareServiceImpl implements ShareService {

    @Autowired
    private ShareRepository shareRepository;
    @Override
    public ResponseInfo addShare(String account, String publisher, String publisherimg, String title, String content, String related_hobby, Long hobbyid, String imgurl, String address) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format.format(new Date());
        Share share = shareRepository.publishShare(account, publisher, publisherimg, title, content, related_hobby, hobbyid, imgurl, address, time);
        return new ResponseInfo(share != null ? "success" : "fail", share != null, share);
    }

    @Override
    public ResponseInfo deleteShare(String account, Long shareid) {
        return null;
    }

    @Override
    public ResponseInfo getShareByAccount(String account) {
        return null;
    }

    @Override
    public String publishShare(HttpServletRequest request, Map<String, Object> map) {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null)
            return "login";
        map.put("user", user);
        map.put("index", "发现动态");
        map.put("title", "发布动态");
        return "addshare";
    }

    @Override
    public String getShareByFriend(HttpServletRequest request, Map<String, Object> map) {
        return null;
    }

    @Override
    public String getShareByHobby(HttpServletRequest request, Map<String, Object> map) {
        return null;
    }
}
